import wilddog from './wilddog'
import xs from 'xstream'
import { getXs } from './util'

let config = {
  syncURL: "https://aiyuke-t.wilddogio.com",
  authDomain: "aiyuke-t.wilddog.com"
}

wilddog.initializeApp(config)

export { wilddog }

const sync = wilddog.sync()

export function DBPlayer () {
  let PlayerRef = sync.ref('Player')
  getXs(this).Player = xs.create({
    start (listener) {
      PlayerRef.on('value', ss => {
        let val = ss.val()
        let key = ss.key()
        listener.next({ val, key })
      })
    },
    stop () {
      return
    }
  })
}

export function DBTournament (self) {
  getXs(this).Tournament = xs.create({
    start (listener) {
      sync.ref('Tournament').on('value', ss => {
        let val = ss.val()
        let key = ss.key()
        listener.next({ val, key })
      })
    },
    stop: () => {}
  })
}

export function DBQuery () {

}
